package org.example;

import java.util.LinkedList;
import java.util.Queue;

public class MyStack1 {
    private Queue<Integer> a;
    private Queue<Integer> b;

    public MyStack1() {
        // 队列a用来辅助导元素
        a = new LinkedList<>();
        b = new LinkedList<>();
    }

    public void push(int x) {
        a.offer(x);
        while (!b.isEmpty()) {
            a.offer(b.poll());
        }
        Queue<Integer> tmp = a;
        a = b;
        b = tmp;
    }


    public int pop() {
        return b.poll();
    }

    public int top() {
        return b.peek();
    }

    public boolean empty() {
        return b.isEmpty();
    }
}
